<template>
  <view class="point-pay">
    <view class="product">
      <view class="img">
        <img :src="ware.waresPic" alt="" />
      </view>
      <view class="content">
        <view class="title">{{ ware.waresName }}</view>
        <view class="amount">
          <text class="text">积分 {{ ware.saleIntegral }}</text>
          <text class="num">x <input type="number" class="inp" v-model="exchangeNum"></text>
        </view>
      </view>
    </view>
    <view class="have">
      <text class="icon1"></text>
      <text class="text">当前可用积分余额 {{ pointInfo.points }}</text>
      <text class="icon2"></text>
    </view>
    <view class="total">
      <view class="text">
        合计：<text class="num">{{ ware.saleIntegral * exchangeNum}}积分</text>
      </view>
      <button @click="pay">提交订单</button>
    </view>
  </view>
</template>

<script>

export default {
  head() {
    return {
      title: "积分兑换确认",
    };
  },
  data() {
    return {
      id: '',
      images: [],
      list: [],
      loading: false, //加载状态
      finished: false, //是否完成加载
      refreshing: false, //是否正在上拉刷新
      img: "/test/pro.png",
      ware: {},
      pointInfo: {},
      exchangeNum: 1,
      sid: '',
    };
  },
  onLoad(e) {
		this.sid = e.sid;
		this.id = e.id;
  },
  computed: {

  },
  created() {
    this.init()
  },
  methods: {
    async init() {
      try {
        const {phoneNumber, enterpriseId} = this;
        const res = await this.$Request({
          url: "/getCustomerPointsInfo",
          method: "GET",
          data: {
            mobilePhone: phoneNumber,
            enterpriseId,
          }
        });

        if (res.retCode === 0) {
          this.pointInfo = res.data
        }
        const res1 = await this.$Request({
          url: "/getIntegralWaresInfo",
          method: "GET",
          data: {
            stationId: this.sid,
          }
        });

        if (res1.retCode === 0) {
          this.ware = res1.data;
        }
      } catch (error) {
        
      }
    },
    async pay() {
      try {
        const {phoneNumber} = this;
        const res = await this.$Request({
          url: "/insertIntegralOrder",
          method: "POST",
          data: {
            waresId: this.id,
            waresName: this.ware.waresName,
            openId: this.openId,
            mobilePhone: phoneNumber,
            // customerName: '',
            exchangeNum: this.exchangeNum,
            integral: this.ware.saleIntegral,
            stationId: this.sid,
          }
        });

        if (res.retCode === 0) {
          uni.navigateTo({
            url: "/subPackB/point/success"
          })
        } else {
          alert("兑换失败");
        }
      } catch (error) {
        
      }
    },
  },
};
</script>

<style>
.point-pay {
  width: 100%;
  background: #f8f8f8;
}
.point-pay .product {
  height: 1.82rem;
  background: #ffffff;
  box-sizing: border-box;
  padding: 0.3rem;
  display: flex;
  justify-content: center;
  align-items: center;
}
.point-pay .product .img {
  width: 2rem;
  height: 1.22rem;
  box-sizing: border-box;
  padding: 0.2rem;
}
.point-pay .product .img img {
  width: 100%;
  height: 100%;
}
.point-pay .product .content {
  width: 5.9rem;
}
.point-pay .product .content .title {
  display: block;
  height: 0.45rem;
  font-size: 0.32rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #0f0f0f;
  line-height: 0.45rem;
}
.point-pay .product .content .amount {
  display: flex;
  justify-content: space-between;
}
.point-pay .product .content .amount .text {
  height: 0.4rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #666666;
  line-height: 0.4rem;
}
.point-pay .product .content .amount .num {
  height: 0.4rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #666666;
  line-height: 0.4rem;
}
.point-pay .product .content .amount .num .inp{
  background:none;  
	outline:none;  
	border:none;
  text-align:right;
  width:0.5rem;
}


.point-pay .have {
  margin-top: 0.22rem;
  height: 1.1rem;
  background: #ffffff;
  position: relative;
}
.point-pay .have .icon1 {
  display: inline-block;
  width: 0.4rem;
  height: 0.35rem;
  background: url("../../../static/point/jifen@2x.png") no-repeat 0 0;
  background-size: 100% 100%;
  position: absolute;
  top: 0.39rem;
  left: 0.3rem;
}
.point-pay .have .text {
  height: 1.1rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #090909;
  line-height: 1.1rem;
  position: absolute;
  left: 0.99rem;
}
.point-pay .have .icon2 {
  display: inline-block;
  width: 0.36rem;
  height: 0.36rem;
  background: url("../../../static/point/xuanzhong@2x.png") no-repeat 0 0;
  background-size: 100% 100%;
  position: absolute;
  right: 0.36rem;
  top: 0.36rem;
}
.point-pay .total {
  width: 7.5rem;
  height: 1.98rem;
  background: #ffffff;
  opacity: 0.95;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: flex-end;
  box-sizing: border-box;
  padding: 0.4rem;
  align-items: center;
}

.point-pay .total .text {
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #111111;
  line-height: 0.4rem;
}
.point-pay .total .text .num {
  width: 1.17rem;
  height: 0.62rem;
  font-size: 0.44rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #111111;
  line-height: 0.62rem;
}
.point-pay .total button {
  border: none;
  background-color: transparent;
  outline: none;
  display: block;
  width: 2.2rem;
  height: 0.8rem;
  background: #fe9700;
  border-radius: 0.45rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 0.4rem;
  margin-left: 0.2rem;
}
</style>
